<template>
	<view class="content">
		<view class="status-bar-height w-100% h-8rpx"></view>
		<view class="w-100% h-98rpx flex-space-between">
			<view class="navigation-title ml-40rpx">
				{{ username }}
			</view>
			<view class="mr-40rpx flex-space-between" @click="quitLoginPopup">
				<image src="@/static/homePage/log_out.png" mode="" class="w-40rpx h-40rpx"></image>
				<span class="log-out ml-16rpx">退出</span>
			</view>
		</view>
		<view class="" v-if="isInspectUser">
			<view class="w-100% h-98rpx flex-space-between">
				<view class="navigation-little-title ml-40rpx">
					质检登记
				</view>
			</view>
			<view class="w-100% h-1rpx" style="background-color: #E7ECED;"></view>
			<view class="flex-wrap-between mr-60rpx ml-60rpx">
				<view class="flex-column-between mt-33rpx mb-18rpx" @click="examine('FirstInspection')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/first_inspection.png" mode=""></image>
					<span>首检</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx" @click="examine('PatrolInspection')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/on-site_inspection.png" mode=""></image>
					<span>巡检</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx" @click="examine('DiscCuttingInspection')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/disc_cutting_inspection.png" mode="">
					</image>
					<span>切盘检</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx" @click="examine('FinalInspection')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/final_inspection.png" mode=""></image>
					<span>终检</span>
				</view>
			</view>
			<view class="flex-wrap-left mr-60rpx ml-60rpx mb-38rpx">
				<view class="flex-column-between mt-33rpx mb-18rpx" @click="examine('FinishedProductInspection')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/finished_product_inspection.png" mode="">
					</image>
					<span>成品检</span>
				</view>
			</view>
		</view>
		
		<view class="" v-if="isDeviceUser">
			<view class="w-100% h-98rpx flex-space-between">
				<view class="navigation-little-title ml-40rpx">
					设备管理
				</view>
			</view>
			<view class="w-100% h-1rpx" style="background-color: #E7ECED;"></view>
			<view class="flex-wrap-between mr-60rpx ml-60rpx mb-38rpx">
				<view class="flex-column-between mt-33rpx mb-18rpx w-96rpx text-wrap-nowrap" @click="examine('DeviceFaultRegister')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/device_fault_register.png" mode="">
					</image>
					<span>故障处理</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx ml-82rpx w-96rpx text-wrap-nowrap" @click="examine('ReadyToClaim')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/ready_to_claim.png" mode="">
					</image>
					<span>备件申领</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx ml-82rpx w-96rpx text-wrap-nowrap" @click="examine('RepairConfirm')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/repair_confirm.png" mode="">
					</image>
					<span>维修确认</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx ml-82rpx w-96rpx text-wrap-nowrap"></view>
			</view>
		</view>
		<view class="pb-67rpx" v-if="isServiceUser">
			<view class="w-100% h-98rpx flex-space-between">
				<view class="navigation-little-title ml-40rpx">
					保养管理
				</view>
			</view>
			<view class="w-100% h-1rpx" style="background-color: #E7ECED;"></view>
			<view class="flex-wrap-between mr-60rpx ml-60rpx">
				<view class="flex-column-between mt-33rpx w-96rpx text-wrap-nowrap" @click="examine('MaintainPlan')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/maintain_plan.png" mode="">
					</image>
					<span>保养计划</span>
				</view>
				<!-- <view class="flex-column-between mt-33rpx ml-82rpx w-96rpx text-wrap-nowrap" @click="examine('MaintainRegister')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/maintain_register.png" mode="">
					</image>
					<span>保养登记</span>
				</view> -->
				<view class="flex-column-between mt-33rpx ml-82rpx w-96rpx text-wrap-nowrap" @click="examine('DeviceInspection')">
					<image class="w-96rpx h-96rpx mb-24rpx" src="@/static/homePage/device_inspection.png" mode="">
					</image>
					<span>设备巡检</span>
				</view>
				<view class="flex-column-between mt-33rpx mb-18rpx ml-82rpx w-96rpx text-wrap-nowrap"></view>
				<view class="flex-column-between mt-33rpx mb-18rpx ml-82rpx w-96rpx text-wrap-nowrap"></view>
			</view>
		</view>
		<u-modal v-model="show" content="是否确定退出登录？" @confirm="quitLogin" :mask-close-able="true" :show-title="false"
			showCancelButton></u-modal>
		<UndataModule></UndataModule>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted } from 'vue'
	import { logout, info,checkOut } from '@/common/api/login'
	import UndataModule from "@/components/undata-module/undata-module.vue";
	const show = ref<boolean>(false)
	// 质检员
	const isInspectUser = ref<boolean>(false);
	// 设备部
	const isDeviceUser = ref<boolean>(false);
	// 保养部
	const isServiceUser = ref<boolean>(false);
	const username = ref<string>('')
	const roleInfo = ref<any>({})
	function quitLoginPopup() {
		show.value = true
	}
	onMounted(async () => {
		const data = {
			tokenId: uni.getStorageSync('token')
		}
		try {
			const list = await info(data);
			if (list.code === 2000) {
				username.value = '欢迎登录：' + list.data.nickName
				uni.setStorageSync('loginName', list.data.nickName);
				uni.setStorageSync('userInfo', list.data);
				getUserCheck();
			} else {
				uni.removeStorageSync('token')
				username.value = '登录信息过期，请重新登录'
				uni.reLaunch({
					url: '/pages/login/login',
					success: () => {
						uni.showToast({
							title: '登录信息过期，请重新登录',
							icon: 'none',
						});
					},
				});
			}
		} catch (error) {
			uni.removeStorageSync('token')
			username.value = '登录信息过期，请重新登录'
			uni.reLaunch({
				url: '/pages/login/login',
				success: () => {
					uni.showToast({
						title: '登录信息过期，请重新登录',
						icon: 'none',
					});
				},
			});
		}
	})
	async function quitLogin() : Promise<void> {
		const data = await logout()
		if (data.code === 2000) {
			uni.removeStorageSync('token')
			uni.reLaunch({
				url: '/pages/login/login',
				success: () => {
					uni.showToast({
						title: '退出登录成功',
						icon: 'none',
					});
				},
			});
			show.value = false
		}
	}
	function examine(data) {
		// if((roleInfo.value.deptName=='生产设备部' || roleInfo.value.admin) && data == 'RepairConfirm'){
		
		uni.navigateTo({
			url: `/pages/${data}/index`
		});
		
	}
	const getUserCheck = ()=> {
		checkOut().then(res=>{
			if(res){
				uni.setStorageSync('roleInfo', res.data);
				roleInfo.value = res.data;
				if(res.data.admin){
					isInspectUser.value = true;
					isDeviceUser.value = true;
					isServiceUser.value = true;
				}else{
					isInspectUser.value = res.data.deptName == '品质部';
					isDeviceUser.value = res.data.deptName == '生产设备部';
					isServiceUser.value = res.data.deptName == '生产设备部';
				}
			}
			
		})
	}
</script>

<style scoped>
	.navigation-title {
		font-size: 34rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #0F1F2D;
		line-height: 34rpx;
	}

	.log-out {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #0F1F2D;
		line-height: 40rpx;
	}

	.navigation-little-title {
		font-size: 28rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #0F1F2D;
		line-height: 34rpx;
	}

	::v-deep .u-model__content__message {
		font-size: 28rpx !important;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #1E1F22;
		padding: 48rpx;
	}

	::v-deep .u-mode-center-box {
		width: 540rpx !important;
		height: 232rpx !important;
		background: #FFFFFF;
		box-shadow: 0px 4px 14px 0px rgba(47, 73, 140, 0.1);
		border-radius: 8rpx;
	}

	::v-deep .u-model__footer__button {
		font-size: 32rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #2F7BFF;
	}
	.text-wrap-nowrap{
		text-wrap:nowrap;
		white-space: nowrap;
	}
</style>